package com.example.sampleapp;

import android.content.Context;
import android.util.Log;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class TableToFile {
    public static void appendToCSV(Context context, String fileName, List<String[]> rowData) {
//        File folder = new File(folderPath);
//        if (!folder.exists()) {
//            folder.mkdirs();
//        }
        File directory = context.getExternalFilesDir(null);
        File file = new File(directory, fileName);

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file, true))) { // true 表示追加写入
            for (String[] row : rowData) {
                writer.write(String.join(",", row)); // 将数组元素用逗号连接
                writer.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}